﻿@using ClassifiedAds.IdentityServer.Models.ClientModels
@model SecretsModel

<form class="secret-form" asp-controller="Client" asp-action="Secrets" Method="post">
    <div class="row">

        <div class="col-12">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a asp-controller="Client" asp-action="Index">Clients</a></li>
                    <li class="breadcrumb-item"><a asp-controller="Client" asp-action="Edit" asp-route-id="@Model.Client.Id">@Model.Client.ClientId</a></li>
                    <li class="breadcrumb-item active" aria-current="page">Client Secrets</li>
                </ol>
            </nav>
        </div>

        <div class="col-md-12">
            <h3>Client Secrets</h3>
        </div>

        <div class="col-md-12">
            <div asp-validation-summary="All" class="text-danger"></div>
        </div>

        <div class="col-md-12">
            <div class="card mt-3">
                <h5 class="card-header">Add Client Secrets</h5>
                <div class="card-body">

                    <!--Hidden -->
                    <input type="hidden" asp-for="Client.Id" />

                    <!--Select-->
                    <div class="form-group row">
                        <label asp-for="Type" class="col-sm-3 col-form-label">
                            @await Html.PartialAsync("_Label", "Secret Type")
                        </label>
                        <div class="col-sm-9">
                            <select asp-for="Type" asp-items="@(new SelectList(Model.TypeList))" class="form-control single-select"></select>
                        </div>
                    </div>

                    <!--Input - text -->
                    <div class="form-group row">
                        <label asp-for="Value" class="col-sm-3 col-form-label">
                            @await Html.PartialAsync("_Label", "Secret Value")
                        </label>
                        <div class="col-sm-9">

                            <div class="input-group mb-3">
                                <input id="secret-input" type="text" autocomplete="off" required class="form-control" asp-for="Value">
                                <div class="input-group-append">
                                    <button type="button" id="generate-guid-button" class="btn btn-primary"><span class="oi oi-random"></span></button>
                                </div>
                            </div>
                            <span asp-validation-for="Value" class="text-danger"></span>
                        </div>
                    </div>

                    <!--Select-->
                    <div class="form-group row">
                        <label asp-for="HashType" class="col-sm-3 col-form-label">
                            @await Html.PartialAsync("_Label", "Hash Type")
                        </label>
                        <div class="col-sm-9">
                            <select asp-for="HashType" asp-items="@(new SelectList(Model.HashTypes))" class="form-control single-select"></select>

                            <div class="alert alert-warning" role="alert">
                                <span class="sr-only">Infor:</span>
                                HashType will be applicable only for the SharedSecret type.
                            </div>
                        </div>
                    </div>

                    <!--Date Picker-->
                    <div class="form-group row">
                        <label asp-for="Expiration" class="col-sm-3 col-form-label">
                            @await Html.PartialAsync("_Label", "Expiration")
                        </label>
                        <div class="col-sm-9">
                            <div class="datepicker input-group date">
                                <input asp-for="Expiration" autocomplete="off" type="text" class="form-control">
                                <div class="input-group-append">
                                    <span class="input-group-text"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!--Input - text -->
                    <div class="form-group row">
                        <label asp-for="Description" class="col-sm-3 col-form-label">
                            @await Html.PartialAsync("_Label", "Secret Description")
                        </label>
                        <div class="col-sm-9">
                            <input type="text" autocomplete="off" class="form-control" asp-for="Description">
                        </div>
                    </div>

                    <!--Button-->
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">
                        </label>
                        <div class="col-sm-9">
                            <button type="submit" class="btn btn-primary">Add</button>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>

<div class="row">
    <div class="col-md-12">
        <div class="card mt-3">
            <h5 class="card-header">Client Secrets</h5>
            <div class="card-body">

                <div class="row table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th></th>
                                <th>Type</th>
                                <th>Value</th>
                                <th>Description</th>
                                <th>Expiration</th>
                                <th>Created</th>
                            </tr>
                        </thead>

                        <tbody>
                            @foreach (var secret in Model.Secrets)
                            {
                                <tr>
                                    <td><a asp-action="DeleteSecret" asp-route-id="@secret.Id" class="btn btn-danger">Remove</a></td>
                                    <td>@secret.Type</td>
                                    <td><button class="secret-value-button btn btn-outline-primary" data-secret-value="@secret.Value"><i class="fa fa-eye"></i></button></td>
                                    <td>@secret.Description</td>
                                    <td>@(secret.Expiration.HasValue ? secret.Expiration.Value.Date.ToShortDateString() : string.Empty)</td>
                                    <td>@secret.Created.Date.ToShortDateString()</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>

                <div class="row">
                    <div class="col-12">
                        @*@await Html.PartialAsync("Common/Pager", new Pager { Action = "ApiSecrets", PageSize = Model.PageSize, TotalCount = Model.TotalCount })*@
                    </div>
                </div>

                <div class="secret-modal modal fade" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="exampleModalLabel"></h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <h2 class="modal-secret-value"></h2>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>